{% extends 'myhome/index.html' %}
{% block title %}
<title>天天生鲜-提交订单</title>
{% endblock %}
{% block main %}
	
	<h3 class="common_title">确认收货地址</h3>
{% for i in addr %}
	<div class="common_list_con clearfix aa">
		<dl>
			<dt>寄送到：</dt>
			<dd><input type="radio" name="{{i}}" checked>
				<span>{{i.shen}}</span>
				<span>{{i.shi}}</span>
				<span>{{i.xian}}</span>
				<span>{{i.zhen}}</span>
				<span>{{i.info}}</span>
				<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;({{i.username}} &nbsp;收)</span>
				<span>&nbsp;联系电话:&nbsp;{{i.phone}}</span>
				<span>&nbsp;&nbsp;&nbsp;邮编：{{i.code}}</span>
			</dd>
		</dl>
		<a target="_blank" href="{% url 'myhome_order_addrIndex' %}?data={{request}}" class="edit_site">编辑收货地址</a>
	</div>
{% endfor %}
	{% if addr %}
	
	{% else %}
	<div class="common_list_con clearfix aa">
		<a target="_blank"  href="{% url 'myhome_order_addrIndex' %}" class="edit_site" style="margin-top: -60px;margin-right: 100px">编辑收货地址</a>
	</div>
	{% endif %}
	<h3 class="common_title">支付方式</h3>	
	<div class="common_list_con clearfix">
		<div class="pay_style_con clearfix bb">
			<input type="radio" name="pay_style" checked>
			<label class="cash">货到付款</label>
			<input type="radio" name="pay_style">
			<label class="weixin">微信支付</label>
			<input type="radio" name="pay_style">
			<label class="zhifubao" style="font-size: 0">支付宝支付</label>
			<input type="radio" name="pay_style">
			<label class="bank">银行卡支付</label>
		</div>
	</div>

	<h3 class="common_title">商品列表</h3>
	
	<div class="common_list_con clearfix">
		<ul class="goods_list_th clearfix">
			<li class="col01">商品名称</li>
			<!-- <li class="col02">商品单位</li> -->
			<li class="col03">商品价格</li>
			<li class="col04">数量</li>
			<li class="col05">小计</li>		
		</ul>
		{% for i in data %}
		<ul class="goods_list_td clearfix">
			<li class="col01" gid={{i.id}}>{{i.ind}}</li>			
			<li class="col02"><img src="{{i.pic_url}}"></li>
			<li class="col03" style="height: 60px;overflow: auto;">{{i.title}}</li>
			<!-- <li class="col04">500g</li> -->
			<li class="col05">{{i.price}}元</li>
			<li class="col06">{{i.num}}</li>
			<li class="col07"><span class="sum">{{i.price_sum}}</span>元</li>	
		</ul>
		{% endfor %}
	</div>
	<h3 class="common_title">总金额结算</h3>

	<div class="common_list_con clearfix">
		<div class="settle_con">
			<div class="total_goods_count">共<em class="num">2</em>件商品，总金额<b class="money"></b></div>
			<div class="transit">运费：<b>包邮</b></div>
			<div class="total_pay">实付款：<b class="money"></b></div>
		</div>
	</div>

	<div class="order_submit clearfix">
		<a href="javascript:void(0)" id="order_btn">提交订单</a>
	</div>	


	<div class="popup_con">
		<div class="popup">
			<p>订单提交成功！</p>
		</div>
		
		<div class="mask"></div>
	</div>
	<script type="text/javascript" src="/static/myhome/js/jquery-1.12.4.min.js"></script>
	<script type="text/javascript">
		$("#order_btn").click(function(){
			//收货地址
			var addr = $(".aa input[type='radio']").filter(':checked').nextAll().text()
			if (addr.length==0){
				alert("请编写收货地址")
				return false
			}
			// 支付方式
			var mode = $(".bb input[type='radio']").filter(':checked').next().text()
			$.get('{% url "myhome_over" %}',{"addr":addr,"mode":mode,"price":price,"gid":String(gid),"num":String(num),"xiao":String(xiao)},function(){
				
			},'json')


			localStorage.setItem('order_finish',2);

			$('.popup_con').fadeIn('fast', function() {

				setTimeout(function(){
					$('.popup_con').fadeOut('fast',function(){
						window.location.href = '{% url 'myhome_cart_index' %}';
					});	
				},3000)
				
			});
		})
		function sum(){
			// 计算总计
			price = 0
			// 商品总数量
			sum = 0
			// 商品id
			gid = []
			// 商品数量
			num = []
			// 小计
			xiao = []
			
			$(".goods_list_td").each(function(ind,el){
				price+=Number($(this).find(".sum").text())
				sum+=1
				gid.push(Number($(this).find(".col01").attr("gid")))
				num.push(Number($(this).find(".col06").text()))
				xiao.push(Number($(this).find(".sum").text()))
			})
			$(".num").text(sum)
			$(".money").text(price.toFixed(2)+"元")
		}
		sum()


	</script>
{% endblock %}